﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Windows.Navigation;
using Agen.Models;
using Agen.ServiceAgencyWPF;
using System.Diagnostics;
using System.ComponentModel;

namespace Agen.Views
{
    public partial class User : Page
    {
        UserVO vo;

        public User()
        {
            InitializeComponent();
            vo = new UserVO();
            DataContext = vo;

        }

        // Executes when the user navigates to this page.
        protected override void OnNavigatedTo(NavigationEventArgs e)
        {

            try
            {
                ApplicationManager.client.GetCustomerInformationCompleted += new EventHandler<GetCustomerInformationCompletedEventArgs>(client_GetCustomerInformationCompleted);
                ApplicationManager.client.GetCustomerInformationAsync(ApplicationManager.CURRENT_CUSTOMER.IdCustomer);
            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }

        void client_GetCustomerInformationCompleted(object sender, GetCustomerInformationCompletedEventArgs e)
        {
            vo.CustomerInformation = e.Result;
        }

        private void manageExam_btn_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("DBG : USER => userList_SelectionChanged ");
            ApplicationManager.FrameAction(this, ApplicationManager.CLICK_ON_MANAGE_CUSTOMER_OFFICIAL_EXAM_HANDLE, new Object());
        }

        private void manageCode_btn_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("DBG : USER => manageCode_btn_Click ");
            ApplicationManager.FrameAction(this, ApplicationManager.CLICK_ON_MANAGE_CUSTOMER_CODE_HANDLE, new Object());
        }

        private void manageFacture_btn_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("DBG : USER => manageFacture_btn_Click ");
            ApplicationManager.FrameAction(this, ApplicationManager.CLICK_ON_MANAGE_CUSTOMER_BILLS_HANDLE, new Object());
        }

        private void manageSession_btn_Click(object sender, RoutedEventArgs e)
        {
            Debug.WriteLine("DBG : USER => manageSession_btn_Click ");
            ApplicationManager.FrameAction(this, ApplicationManager.CLICK_ON_MANAGE_CUSTOMER_SESSION_HANDLE, new Object());
        }

        private void cancel_button_Click(object sender, RoutedEventArgs e)
        {
            ApplicationManager.FrameAction(this, ApplicationManager.PREVIOUS_HANDLE, new Object());
        }

       

    }

    public class UserVO : INotifyPropertyChanged {

        private CustomerInformationDC _customerInformation;


        public UserVO() {
            _customerInformation = new CustomerInformationDC();
        }

        public CustomerInformationDC CustomerInformation { 
            get
            {
                return this._customerInformation;
            }
            set
            {
                this._customerInformation = value;
                OnPropertyChanged("CustomerInformation");
            } 
        }


        public event PropertyChangedEventHandler PropertyChanged;

        private void OnPropertyChanged(string property)
        {
            if (PropertyChanged != null)
            {
                PropertyChanged(this, new PropertyChangedEventArgs(property));
            }
        }
    }
}
